package controllers;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import entities.Domain;

import systems.RecentlyDomain;

import models.DomainModel;

public class RssServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException {
		response.setContentType("text/xml");

		List<String> ids = RecentlyDomain.getDomains();
		DomainModel domainModel = DomainModel.getInstance();
		
		List<String> listId = new ArrayList<String>();
		for (int i = 0; i < ids.size(); i++) {
			if (i > 10) break;
			listId.add(ids.get(i));
		}
		
		List<Domain> domains = domainModel.getByListId(listId);
	    
		request.setAttribute("domains", domains);
		try {
			request.getRequestDispatcher("/pages/rss.jsp").forward(request, response);
		} catch (ServletException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
